<template>
  <div>
    <div class="box">
      <div
        class="goods"
        v-for="item in newList"
        :key="item.id"
        @click="ruFn(item.id, item.isHave)"
      >
        <div class="bgimg">
          <img :src="item.img" alt="" />
        </div>
        <div class="describe">
          <p>
            <span class="qh" v-if="!item.isHave">缺货</span>
            <span class="zy" v-if="item.isDirect">直营</span>
            <span class="title">{{ item.name }}</span>
          </p>
          <div class="al">
            <span class="price">￥{{ item.price }}</span>
            <span class="total">销量：{{ item.volume }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import token from "@/utils/token";
// import { getGoodsList } from "@/api/goodsList";
export default {
  data() {
    return {
      // list: [],
    };
  },
  props: {
    newList: Array,
  },
  // async created() {
  //   try {
  //     let res = await getGoodsList(token);
  //     //   console.log(res);
  //     this.list = res.data.data.list;
  //     // console.log(this.list);
  //   } catch (error) {
  //     console.log(error);
  //   }
  // },
  methods: {
    ruFn(id, isHave) {
      if (!isHave) {
        this.$toast.fail("商品缺货");
        return;
      }
      this.$router.push({ path: "/goodsDetails", query: { goodsId: id } });
    },
  },
  created() {},
};
</script>

<style scoped lang="less">
.box {
  width: 730px;
  column-count: 2;
  -webkit-column-count: 2;
  position: relative;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  .goods {
    // width: 48%;
    height: auto;
    -webkit-column-break-inside: avoid;
    border-radius: 10px;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    margin-bottom: 8px;
    margin-right: 8px;
    display: inline-block;
    .bgimg {
      width: 340px;
      img {
        width: 100%;
        margin-left: 2px;
        margin-top: 5px;
      }
    }
    .describe {
      p {
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        .qh {
          font-size: 13px;
          padding: 0 5px;
          width: 36px;
          height: 18px;
          background-color: #909090;
          color: #fff;
          text-align: center;
          display: inline-block;
        }
        .zy {
          font-size: 13px;
          padding: 0 5px;
          width: 36px;
          height: 18px;
          background-color: #d81e06;
          color: #fff;
          text-align: center;
          display: inline-block;
        }
        .title {
          font-size: 16px;
          color: #333;
        }
      }
      .al {
        position: relative;
        .price {
          margin-left: 5px;
          font-size: 18px;
          color: #d81e06;
          display: inline-block;
        }
        .total {
          position: absolute;
          right: 5px;
          bottom: 0;
          font-size: 16px;
          color: #999;
          display: inline-block;
        }
      }
    }
  }
}
</style>
